<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script type="text/javascript" src="../js/global.js"></script>
	</head>
	<body>
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
			<legend>题库</legend>
		</fieldset>
		
		<div id="searchePage" class="layui-form-item" style="margin-top: 10px;margin-left: 10px;">
			<form class="layui-form" method="post" onsubmit="return false;">
				<label class="layui-form-mid">试卷名称:</label>
				<div class="layui-input-inline" style="width: 100px;">
					<input type="text" id="testPaperName" name="testPaperName" autocomplete="off"
						class="layui-input" />
				</div>
				<label class="layui-form-mid">状态:</label>
				<div class="layui-input-inline" style="width: 100px;">
					<select class="qu" id="status" name="status">
								<option value=""></option>
								<option value="0">未开考</option>
								<option value="1">已结束</option>
							</select>
				</div>
				<label class="layui-form-mid">考试时长:</label>
				<div class="layui-input-inline" style="width: 100px;">
					<input type="number" id="testPaperTime" name="testPaperTime" autocomplete="off"
						class="layui-input" />
				</div>
                <div class="layui-input-inline" style="width: 70px;">
					<button class="layui-btn" id="search" data-type="reload">搜索</button>
				</div>
				<div class="layui-input-inline">
					<button class="layui-btn add" lay-event="createClass" id="addPage">添加</button>
				</div>
			</form>
			
		</div>
		<!--
			编辑弹层
		-->
		<div id="updatePage" style="display: none;">
			<form class="layui-form" action="" onsubmit="return false" lay-filter="updateForm">
				<div class="layui-form-item">
					<label class="layui-form-label">试卷名称</label>
					<div class="layui-input-block">
						<input  type="text" disabled="disabled" name="testPaperName" class="layui-input">
						<input  type="hidden" name="testPaperId">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">试卷状态</label>
					<div class="layui-input-block">
						<input  type="text" disabled="disabled" name="status"  class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">科目:</label>
					<div class="layui-input-block">
						<select class="su"  disabled="disabled" name="questionTypeId">
							<option></option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">考试时长</label>
					<div class="layui-input-block">
						<input  type="number" name="testPaperTime" lay-verify="required" 
						 class="layui-input">
					</div>
				</div>
			</form>
		</div>
		 <table  id="q_table" lay-filter="test">
		
		<!--
        	数据表格
        -->
	<input type="text" hidden="hidden" id="tid" />
    <table class="layui-hide" id="class_table" lay-filter="test">
		
	</table>
   <!--行内工具栏-->
   <script type="text/html" id="barDemo">
	   <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="release">发布考试</a>
	
   	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
   	<a class="layui-btn layui-btn-xs" lay-event="update">编辑</a>
   </script>
   <script type="text/html" id="sta">
	    {{# if(d.status==0){ }}
	     未开始
	   {{# } else { }}
	     已结束
	    {{# } }}
	  
   </script>
  
		
        
</body>
	<script>
			layui.use(['table', 'form', 'layer', 'laydate', 'upload', 'element'],function(){
				var layer = layui.layer;
				var form = layui.form;
				var table = layui.table;
				var laydate = layui.laydate;
				var upload = layui.upload;
				var element = layui.element;
				var $ = layui.$;
				//渲染用户表
				$.get(globalData.examinationServer + '/subject/listSubjects', function(res) {
					var html = "";
					for (var i = 0; i < res.data.length; i++) {
						html += "<option value=" + res.data[i].subjectId + ">" + res.data[i].subjectName + "</option>"
				
					}
					$(".su").append(html);
				
					form.render('select')
				}, "json")
				//渲染数据表格
				table.render({
					elem:'#class_table',
					height:400,
					url:globalData.examinationServer + '/testPaper/listTestPapers',
					method:"get",
					toolbar: '#topToolbar',
					//headers: {token: globalData.getCurToken()},//设置请求头
					title:"用户表",
					page:true,
					cols:[
							[
							{
								field:'testPaperName',
								title:'试卷名称',
								sort:true,
								align:'center'
							},{
								field:'status',
								title:'试卷状态',
								templet:'#sta'
							},{
								field: 'testPaperTime',
								title: '考试时长',
								sort:true,
								align:'center'
							},{
								field: 'subjectId',
								title: '所属科目',
								templet:'<div>{{subject(d.subjectId)}}</div>'
							},{
								title:'操作',
								align:"center",
								toolbar:'#barDemo'
							}
							]
						],
						id:"testReload",
						done:function(res,curr,count){
						
						}
					});
						
						//添加班级弹出层
						$("#addPage").on('click',function(){
							//$(".add").append('<a href="javascript:;" _href="testPaper_add.html">  </a>' )
						 //	window.open('testPape"r_add.html'); 
						
							layer.open({
								type:2,
								title:'添加试题',
								area: ['1200px', '700px'],
								content:'testPaper_add.html',
								end:function(){
									//alert(1)
								}
							});
						});
				
				
				active={
					reload:function(){
						var testPaperName=$("#testPaperName");
						var status=$("#status");
						var beginDate=$("#beginDate");
						var endDate=$("#endDate");
						console.log(status.val())
						table.reload('testReload',{
							where:{
								'testPaperName':testPaperName.val(),
								'status':status.val(),
								'beginDate':beginDate.val(),
								'endDate':endDate.val()
								},
							curr:{
								page:1
							}
						});
					}
				};
				
				//查询操作
				$("#search").on('click',function(){
					var type=$(this).data('type');
					active[type]?active[type].call(this):'';
				})
				
				
				
//			
	          //行内工具栏监听
				table.on('tool(test)',function(obj){
					var data=obj.data;
					
					switch(obj.event){
						case 'del':{
						layer.confirm('确认删除该试题的信息吗?',{icon:7},function(index){
							layer.close(index);
						   $.ajax({
								type : "delete",
								url : globalData.examinationServer+'/testPaper/deleteTestPaper',
								data:{
											testPaperId:data.testPaperId
										},//需要传递到服务端的数据
										dataType:'json',//服务端响应数据类型
										xhrFields: {
											withCredentials: true
										},
										// beforeSend: function(request) {
										// 	request.setRequestHeader("token", globalData.getCurToken());
										// },
										success : function(res) {
											if(res.code == 0){
												layer.msg(res.msg,{icon:1,time:2000},function(index){
													table.reload('testReload');
												});
												
											}else{
												layer.msg(res.msg,{icon:2,time:2000});
											}
									}
									});
									
								});
								}
						break;
						case 'update':
						var update_index=layer.open({

								type:2,
								title:'添加试题',
								area: ['1100px', '700px'],
								content:'update_question.html',
								scrollbar: false,
								data:data,
                                success: function (layero, index) {
								    //向layer页面传值，传值主要代码
								    var body = layer.getChildFrame('body', index);
								    //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
								     //var iframeWin = window[layero.find('iframe')[0]['name']];
								    //将弹窗页面中属性名name="testPaperName"的标签赋值
								    body.find("[name='testPaperName']").val(data.testPaperName);
									body.find("[name='testPaperId']").val(data.testPaperId);
									body.find("[name='status']").val(data.status);
									body.find("[name='testPaperTime']").val(data.testPaperTime);
								                        }
						});
						
							break;
							//详情
							case 'detail':
							//表单赋值
							form.val('detailForm',data);
								var detaile_index=layer.open({
								type:1,
								//title:'您正在修改本题的信息',
								area: ['600px', '600px'],
								content: $('#detailPage'),
								success:function(layero,index){
								//修改提交
	
								}
							});
						
							break;
							case 'release':
							var tid=$("#tid").val(data.testPaperId);
							
							  layer.open({
							  	type:2,
							  	title:'发布考试',
							  	area: ['700px', '700px'],
							  	content:'exam_add.html',
							  	end:function(){
							  		//alert(1)
							  	}
							  });
						
					}
				});
				

			});
			
			//应用template模板，渲染专业
			    function subject(subjectId){
					var sId = subjectId;
			        var title;
			        $.ajax({
			            url:globalData.examinationServer+ '/subject/listSubjects',//你的后台请求路径
			            dataType:'json',
			            async: false,//同步
			            success:function(data){
							$.each(data.data,function (index,obj) {
								//console.log("q"+qId);
								console.log(data.data);
								//console.log(obj.questionTypeId==qId);
									 if(obj.subjectId==sId){
										title=obj.subjectName;
			                             
			                        }
			                    });
			            }
			        });
			        return title;
			    };

			
		</script>
</html>
<!-- <script type="text/html" id="demo">
   	{{# if(d.questionTypeId == 0){ }}
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="单选" checked="">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="多选">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="填空">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="判断">
     <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="问答">
	 {{# if(d.questionTypeId == 1){ }}
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="单选" >
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="多选" checked="">
      <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="填空">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="判断">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="问答">
	 {{# if(d.questionTypeId == 2){ }}
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="单选" >
	
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="多选">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="填空" checked="">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="判断">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="问答">
	 {{# if(d.questionTypeId == 3){ }}
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="单选" >

	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="多选">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="填空" >
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="判断" checked="">
	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="问答">
   {{# }else{ }}
   	 <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="单选" >
     <input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="多选">
   		<input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="填空" >
   		<input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="判断" >
   		<input name="questionTypeId" value="{{d.questionTypeId}}" type="radio" title="问答" checked="">
   	{{# } }}
   </script> -->